package edu.maping.easy.gui;

import processing.core.PApplet;
import processing.core.PGraphics;
import fisica.FBox;

public class Slider extends FBox {

	public String name;
	public float value = 0;
	public float maxValue = 0;
	public float minValue = 0;
	float x, y = 0;
	private float noWorld = -2357;

	public Slider(String name, float width, float height, float value,
			float maxValue, float minValue) {

		super(width, height);
		this.value = value;
		this.maxValue = maxValue;
		this.minValue = minValue;
		this.name = name;
	}

	public void draw(PGraphics applet) {
		super.draw(applet);
		preDraw(applet);

		applet.fill(0, 255, 0);
		applet.rectMode(PApplet.CORNER);
		applet.rect(-getWidth() / 2, -getHeight() / 2, value * getWidth()
				/ maxValue, getHeight());

		applet.fill(255);
		applet.textAlign(PApplet.CENTER);
		applet.textSize(12);
		applet.text(name + ":" + value, 2, 5);
		// applet.rectMode(PApplet.CORNER);
		postDraw(applet);
	}

	public void setValue(int x, int y) {
		float value = x - (getX() - getWidth() / 2);
		this.value = value * maxValue / getWidth();
		if (this.value > maxValue) {
			this.value = maxValue;
		}
		if (this.value < minValue) {
			this.value = minValue;
		}
	}

	public float getValue() {
		return value;
	}

	public void setValue(float value) {
		this.value = value;
	}

	@Override
	public void setDrawable(boolean drawable) {
		super.setDrawable(drawable);
//		if (drawable == false) {
//			x = getX();
//			y = getY();
//			super.setPosition(noWorld, noWorld);
//		} else {
//			super.setPosition(x, y);
//		}
	}

	@Override
	public void setPosition(float x, float y) {
//		this.x = x;
//		this.y = y;
//
//		if (isDrawable())
			super.setPosition(x, y);
	}

}
